package com.demo.controller;

import com.demo.service.StudentService;
import com.demo.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@Api
public class StudentController {

    @Autowired
    StudentService studentService;

    @ApiOperation("根据学号查询姓名")
    @RequestMapping("/getname")
    public String getName(String sid){
        return studentService.getStuByNo(sid).getName();
    }

    @ApiOperation("取得所有班级信息")
    @RequestMapping("/getAllClass")
    public Result getAllClass(){
        Result result = new Result();
        result.setCode(1);
        result.setMessage("success");
        result.setHeaders(null);
        List<HashMap<String,String>> data = new ArrayList<>();
        List<String> classno = studentService.getAllClass();
        for (String i: classno
        ) {
            HashMap<String,String> temp = new HashMap<>();
            temp.put("id",i);
            temp.put("name",i);
            data.add(temp);
        }
        result.setData(data);
        return result;
    }

}
